﻿using System;
using ART.Common;

namespace ART.Admini.Users
{
    public partial class AdminDetail : System.Web.UI.Page
    {
        protected int Id = 0;
        private ART.BLL.B_TBAdmin bll = new ART.BLL.B_TBAdmin();
        private ART.Model.M_TBAdmin model = new ART.Model.M_TBAdmin();

        protected void Page_Load(object sender, EventArgs e)
        {
            Id = Common.LYRequest.GetInt("id", 0);
            if (!IsPostBack)
            {
                InitData();
            }
        }
        private void InitData()
        {
            JBind.BindList(dropGroupId, new BLL.B_Roles().GetList("").Tables[0], "RoleName", "id");
            if (Id > 0)
            {//edit
                model = bll.GetModel(Id);
                if (model != null)
                {
                    chkSuperTF.Checked = model.SuperTF;
                    //txtPowerList.Text = model.PowerList;
                    txtUserName.Text = model.UserName;
                    //txtPassWord.Text = model.PassWord;
                    litPWD.Text = "不修改请留空！";
                    txtRealName.Text = model.RealName;
                    dropGroupId.SelectedValue = model.RolesId.ToString();
                    
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs p1)
        {
            if (Id > 0)
            {
                #region __________Edit__________
                model = bll.GetModel(Id);
                model.SuperTF = chkSuperTF.Checked;
                //model.PowerList = txtPowerList.Text;
                model.UserName = txtUserName.Text;
                model.RolesId = Utils.StrToInt(dropGroupId.SelectedValue, 0);
                if (txtPassWord.Text!="")
                {
                    model.PassWord = Utils.SHA256(txtPassWord.Text);
                }
                model.RealName = txtRealName.Text;
                if (bll.Update(model))
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.edit, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
            else
            {
                #region __________Add__________
                model.SuperTF = chkSuperTF.Checked;
                //model.PowerList = txtPowerList.Text;
                model.UserName = txtUserName.Text;
                model.PassWord = Utils.SHA256(txtPassWord.Text);
                model.RealName = txtRealName.Text;
                model.AddDate = DateTime.Now;
                model.LastLoginIP = "";
                model.LastLoginTime = DateTime.Now;
                model.LoginTimes = 1;
                model.RolesId = Utils.StrToInt(dropGroupId.SelectedValue, 0);
                if (bll.Add(model) > 0)
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.add, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
        }
    }
}
